<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Biodata_model extends CI_Model {

	function __construct()
	{
		parent::__construct();
    }

	function getDetailBiodata($nim)
	{
	    $query = "SELECT * FROM view_data_mahasiswa where `NIM`='$nim'";
        $query = $this->db->query($query);

        if($query->num_rows()>0){
          $data = $query->row();
        }
        else $data = NULL;
        return $data;
	}

    function updateDetailBiodata()
    {
        $tanggal_lahir = $this->input->post('thn_lahir').'-'.$this->input->post('bln_lahir').'-'.$this->input->post('tgl_lahir');

        $query = "UPDATE mahasiswa SET
					`TEMPAT_LAHIR` = '{$this->input->post('tempat_lahir')}',
					`TANGGAL_LAHIR` = '{$tanggal_lahir}',
					`ALAMAT_ASAL` = '{$this->input->post('alamat_asal')}',
					`ALAMAT` = '{$this->input->post('alamat')}',
					`AGAMA` = '{$this->input->post('agama')}',
					`ASAL_SMA` = '{$this->input->post('asal_sma')}',
					`NO_TELP` = '{$this->input->post('no_telp')}',
					`NAMA_AYAH` = '{$this->input->post('nama_ayah')}',
					`NAMA_IBU` = '{$this->input->post('nama_ibu')}',
					`PEKERJAAN_AYAH` = '{$this->input->post('pekerjaan_ayah')}',
					`PEKERJAAN_IBU` = '{$this->input->post('pekerjaan_ibu')}',
					`PENGHASILAN_AYAH` = '{$this->input->post('penghasilan_ayah')}',
					`PENGHASILAN_IBU` = '{$this->input->post('penghasilan_ibu')}'
					WHERE `NIM` = '".$this->session->userdata('siamunp_user')."' LIMIT 1
				 ";

        $query = $this->db->query($query);

        if($query)
        {
          return TRUE;
        }
        else
        {
          return FALSE;
        }
     }

     function getPassMhs($nim, $pwd_lama)
	 {
	    $pwd_lama = md5($pwd_lama);
	    $query = "SELECT * FROM `view_pass_mahasiswa` where `NIM`='$nim' and `PASSWORD`='$pwd_lama'";
        $query = $this->db->query($query);

        if($query->num_rows()>0){
          $data = $query->num_rows();
        }
        else $data = NULL;
        return $data;
	 }

     function updatePassMhs($nim, $pwd_baru)
	 {
	    $pwd_baru = md5($pwd_baru); 
	    $query = "UPDATE mahasiswa SET `PASSWORD` = '$pwd_baru' WHERE NIM = '$nim'";
        $query = $this->db->query($query);
     }
}

